<template>
  <div class="container">
    <div class="top-box">
      <div class="left-box">
        <div class="color-box"></div>
        <p>新增设备</p>
      </div>
      <div class="right-box">
        <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Return">返回</el-button>
      </div>
    </div>
    <div class="content-box">
      <div class="table-box">
        <div class="item-box">
          <div class="number-box">设备编号</div>
          <div class="number1-box">
            <input type="text" v-model="item.equipmentNumber" placeholder="请输入设备编号" />
          </div>
        </div>
        <div class="item-box">
          <div class="number-box">设备名称</div>
          <div class="number1-box">
            <input type="text" v-model="item.name" placeholder="请输入设备名称" />
          </div>
        </div>
        <div class="item-box">
          <div class="number-box">设备地址</div>
          <div class="number1-box">
            <input type="text" v-model="item.address" placeholder="请输入设备地址" />
          </div>
        </div>
        <div class="item-box">
          <div class="number-box">购入时间</div>
          <div class="number1-box">
            <template>
              <div class="block">
                <el-date-picker
                  v-model="item.buyTime"
                  type="date"
                  placeholder="选择日期"
                  style="width:50%;"
                ></el-date-picker>
              </div>
            </template>
          </div>
        </div>
      </div>
      <div class="btn-box">
        <el-button type="primary" @click="addlist()">确定</el-button>
        <el-button type="info" @click="Return">返回</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  data () {
    return {
      item: { equipmentNumber: "", name: "", address: "", buyTime: "", creater: 0 },
      Mark: 0,
    }
  },
  created () {
    this.item.creater = JSON.parse(localStorage.getItem("message")).Id;
  },
  methods: {
    Return () {
      window.history.go(-1);
    },
    addlist () {
      if (this.Mark == 0) {
        if (this.item.equipmentNumber == "") { this.$message.error("设备编号非空"); return; }
        if (this.item.name == "") { this.$message.error("设备名称非空"); return; }
        if (this.item.address == "") { this.$message.error("设备地址非空"); return; }
        if (this.item.buyTime == "") { this.$message.error("购买时间非空"); return; }
        var objs = JSON.stringify(this.item); let the = { index: 4, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/AdministrationManage.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);
          } else {
            this.$message.error(list.tip); this.Mark = 0;
          }
        });
      }
    },
  }
}
</script>
<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.top-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  // border: 1px solid $red;
}
.left-box {
  width: 100px;
  height: 40px;
  float: left;
  margin-top: 10px;
  overflow: hidden;
  margin-left: 1%;
  // border: 1px solid red;
}
.color-box {
  width: 5px;
  height: 20px;
  float: left;
  margin-top: 10px;
  background-color: $Header_color;
}
.left-box p {
  float: left;
  margin-left: 5px;
  line-height: 40px;
}
.right-box {
  float: right;
  width: 90px;
  height: 40px;
  margin-right: 2%;
  border-radius: 8px;
  margin-top: 10px;
  background-color: $return-color;
  // border: 1px solid red;
}
.right-box:hover {
  background-color: #a4a6ad;
}
.right-box span {
  float: left;
  color: $white;
  font-size: $font-size-medium;
  line-height: 40px;
  //  border: 1px solid red;
}
.right-box img {
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 6px;
  float: left;
  // border: 1px solid red;
}
.content-box {
  width: 98%;
  height: 800px;
  margin: 0 auto;
  border-radius: 8px;
  background-color: $white;
  border: 1px solid $bordercolor;
}
.table-box {
  width: 50%;
  height: 243px;
  margin: 0 auto;
  margin-top: 200px;
  border: 1px solid $bordercolor;
}
.item-box {
  width: 100%;
  height: 60px;
  display: flex;
  border-bottom: 1px solid $bordercolor;
}
.number-box {
  width: 20%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  color: $blackcolor;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
}
.number1-box {
  flex: 1;
}
.number1-box input {
  width: 90%;
  height: 60px;
  border: none;
  outline: none;
  font-size: 14px;
  color: #515151;
  margin-left: 10%;
  // text-align: center;
}
.block {
  // text-align: center;
  margin-top: 10px;
  margin-left: 10%;
}
.btn-box {
  width: 20%;
  height: 60px;
  margin: 0 auto;
  padding-left: 100px;
  margin-top: 100px;
  // border: 1px solid red;
}
</style>
